package com.web.orderservice.controller;

import com.web.orderservice.entity.Order;
import com.web.orderservice.entity.Product;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class OrderController {

    @Resource
    private RestTemplate restTemplate;

    @RequestMapping("/order/{id}")
    public ResponseEntity<Order> getOrderById(@PathVariable Long id){
        ResponseEntity<Product> entity = restTemplate.getForEntity("http://product-service/product/10", Product.class);
//        ResponseEntity<Product> entity = restTemplate.getForEntity("http://localhost:8002/product/10", Product.class);
        Order order = new Order(id,10L,entity.getBody());
        return ResponseEntity.ok(order);
    }
}
